count down from G_MAXUINT to avoid clashes with application-added DND
authorMichael Natterer <mitch@imendio.com>
Wed, 22 Mar 2006 10:39:51 +0000 (10:39 +0000)
committerMichael Natterer <mitch@src.gnome.org>
Wed, 22 Mar 2006 10:39:51 +0000 (10:39 +0000)
2006-03-22  Michael Natterer  <mitch@imendio.com>

* gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): count down
from G_MAXUINT to avoid clashes with application-added DND
targets.

* gtk/gtktextview.c (gtk_text_view_init): set an empty
GtkTargetList on the drag_dest so it is not NULL when a derived
class' init() function is called.

(gtk_text_view_target_list_notify): copy the text buffer's paste
targets into the view's destinstion target list (preserving
application-added DND targets), instead of replacing the view's
target list. Fixes bug #334399.

ChangeLog
ChangeLog.pre-2-10
gtk/gtktextbuffer.h
gtk/gtktextview.c

index 356f5e12473d594edc8c32700414fd8d0bb767ed..a78ce473469e1e6f0338c83e5cbef90184ffe785 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2006-03-22  Michael Natterer  <mitch@imendio.com>
+
+       * gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): count down
+       from G_MAXUINT to avoid clashes with application-added DND
+       targets.
+
+       * gtk/gtktextview.c (gtk_text_view_init): set an empty
+       GtkTargetList on the drag_dest so it is not NULL when a derived
+       class' init() function is called.
+
+       (gtk_text_view_target_list_notify): copy the text buffer's paste
+       targets into the view's destinstion target list (preserving
+       application-added DND targets), instead of replacing the view's
+       target list. Fixes bug #334399.
+
 2006-03-21  Anders Carlsson  <andersca@imendio.com>
 
         * gtk/Makefile.am:
index 356f5e12473d594edc8c32700414fd8d0bb767ed..a78ce473469e1e6f0338c83e5cbef90184ffe785 100644 (file)
@@ -1,3 +1,18 @@
+2006-03-22  Michael Natterer  <mitch@imendio.com>
+
+       * gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): count down
+       from G_MAXUINT to avoid clashes with application-added DND
+       targets.
+
+       * gtk/gtktextview.c (gtk_text_view_init): set an empty
+       GtkTargetList on the drag_dest so it is not NULL when a derived
+       class' init() function is called.
+
+       (gtk_text_view_target_list_notify): copy the text buffer's paste
+       targets into the view's destinstion target list (preserving
+       application-added DND targets), instead of replacing the view's
+       target list. Fixes bug #334399.
+
 2006-03-21  Anders Carlsson  <andersca@imendio.com>
 
         * gtk/Makefile.am:
index 7d69a600d51b3e9a6c160350864f669d651f13a6..79f969ccfaa6236b3c4c3e4b0e389e8a46761206 100644 (file)
@@ -43,12 +43,15 @@ G_BEGIN_DECLS
 
 /* these values are used as "info" for the targets contained in the
  * lists returned by gtk_text_buffer_get_copy,paste_target_list()
+ *
+ * the enum counts down from G_MAXUINT to avoid clashes with application
+ * added drag destinations which usually start at 0.
  */
 typedef enum
 {
-  GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS,
-  GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT,
-  GTK_TEXT_BUFFER_TARGET_INFO_TEXT
+  GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS = G_MAXUINT - 0,
+  GTK_TEXT_BUFFER_TARGET_INFO_RICH_TEXT       = G_MAXUINT - 1,
+  GTK_TEXT_BUFFER_TARGET_INFO_TEXT            = G_MAXUINT - 2
 } GtkTextBufferTargetInfo;
 
 typedef struct _GtkTextBTree GtkTextBTree;
index 3049fae6dcba1e1110b7305d96877818b8291b2e..9b029f4ef66194a423320991458c1a9c2e7642e2 100644 (file)
@@ -1044,9 +1044,8 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
 static void
 gtk_text_view_init (GtkTextView *text_view)
 {
-  GtkWidget *widget;
-
-  widget = GTK_WIDGET (text_view);
+  GtkWidget *widget = GTK_WIDGET (text_view);
+  GtkTargetList *target_list;
 
   GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
 
@@ -1065,6 +1064,10 @@ gtk_text_view_init (GtkTextView *text_view)
   gtk_drag_dest_set (widget, 0, NULL, 0,
                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
 
+  target_list = gtk_target_list_new (NULL, 0);
+  gtk_drag_dest_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+
   text_view->virtual_cursor_x = -1;
   text_view->virtual_cursor_y = -1;
 
@@ -6159,6 +6162,7 @@ gtk_text_view_drag_motion (GtkWidget        *widget,
   GtkTextIter end;
   GdkRectangle target_rect;
   gint bx, by;
+  GdkAtom target;
   GdkDragAction suggested_action = 0;
   
   text_view = GTK_TEXT_VIEW (widget);
@@ -6180,8 +6184,10 @@ gtk_text_view_drag_motion (GtkWidget        *widget,
                                      &newplace,
                                      bx, by);  
 
-  if (gtk_drag_dest_find_target (widget, context,
-                                 gtk_drag_dest_get_target_list (widget)) == GDK_NONE)
+  target = gtk_drag_dest_find_target (widget, context,
+                                      gtk_drag_dest_get_target_list (widget));
+
+  if (target == GDK_NONE)
     {
       /* can't accept any of the offered targets */
     }                                 
@@ -6887,7 +6893,45 @@ gtk_text_view_target_list_notify (GtkTextBuffer    *buffer,
                                   const GParamSpec *pspec,
                                   gpointer          data)
 {
-  gtk_drag_dest_set_target_list (data, gtk_text_buffer_get_paste_target_list (buffer));
+  GtkWidget     *widget = GTK_WIDGET (data);
+  GtkTargetList *view_list;
+  GtkTargetList *buffer_list;
+  GList         *list;
+
+  view_list = gtk_drag_dest_get_target_list (widget);
+  buffer_list = gtk_text_buffer_get_paste_target_list (buffer);
+
+  if (view_list)
+    gtk_target_list_ref (view_list);
+  else
+    view_list = gtk_target_list_new (NULL, 0);
+
+  list = view_list->list;
+  while (list)
+    {
+      GtkTargetPair *pair = list->data;
+      guint          info;
+
+      list = g_list_next (list); /* get next element before removing */
+
+      for (info = GTK_TEXT_BUFFER_TARGET_INFO_BUFFER_CONTENTS;
+           info >= GTK_TEXT_BUFFER_TARGET_INFO_TEXT;
+           info--)
+        {
+          if (pair->info == info)
+            gtk_target_list_remove (view_list, pair->target);
+        }
+    }
+
+  for (list = buffer_list->list; list; list = g_list_next (list))
+    {
+      GtkTargetPair *pair = list->data;
+
+      gtk_target_list_add (view_list, pair->target, pair->flags, pair->info);
+    }
+
+  gtk_drag_dest_set_target_list (widget, view_list);
+  gtk_target_list_unref (view_list);
 }
 
 static void